/**
 * 
 */
package edu.buu.refectory.service;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.buu.refectory.domain.Cart;
import edu.buu.refectory.domain.CartItem;
import edu.buu.refectory.domain.Food;
import edu.buu.refectory.utils.CommonUtil;

/**
 * @author Bruce<br>
 * @version 1.0<br>
 * @CreateDate 1 May 2016 <br>
 */
@Service
public class CartService {

	@Autowired
	private FoodService foodService;
	
	/**
	 * @param fId
	 * @param session
	 * @return
	 */
	public Cart addCart(Integer fId, HttpSession session) {
		Cart cart = CommonUtil.getCart(session);
		Food food = foodService.getById(fId);
		CartItem cartItem = new CartItem();
		cartItem.setFood(food);
		cartItem.setCount(1);
		cart.addCart(cartItem);
		return cart;
	}

}
